package com.openlab.service.notice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.openlab.service.notice.dto.NoticeDetailInfo;
import com.openlab.service.notice.dto.NoticeInfoDto;
import com.openlab.service.notice.entity.NoticeToUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @Author
 */
@Repository
public interface NoticeToUserMapper extends BaseMapper<NoticeToUser> {

    @Select("<script> select "+
            "SQL_CALC_FOUND_ROWS ejyy_notice_to_user.id,"+
            "ejyy_notice_to_user.title," +
            "ejyy_notice_to_user.published,"+
            "ejyy_notice_to_user.published_at,"+
            "ejyy_notice_to_user.notice_tpl_id,"+
            "ejyy_notice_to_user.created_by,"+
            "ejyy_notice_to_user.created_at,"+
            "ejyy_property_company_user.real_name "+
            "from ejyy_notice_to_user left join ejyy_property_company_user on ejyy_property_company_user.id = ejyy_notice_to_user.created_by "+
            "where ejyy_notice_to_user.community_id = #{community_id} "+
            "<when test = 'published != null'> and ejyy_notice_to_user.published = #{published} </when>"+
            " order by ejyy_notice_to_user.id desc </script>"

    )
    IPage<NoticeInfoDto> selectPageVo(IPage page, @Param("published") Integer published, @Param("community_id") Long community_id);


    @Select("select" +
            "                ejyy_notice_to_user.id," +
            "                ejyy_notice_to_user.title," +
            "                ejyy_notice_to_user.overview," +
            "                ejyy_notice_to_user.content," +
            "                ejyy_notice_to_user.created_at," +
            "                ejyy_notice_to_user.notice_tpl_id," +
            "                ejyy_notice_to_user.published," +
            "                ejyy_notice_to_user.published_at," +
            "                ejyy_notice_to_user.created_by," +
            "                ejyy_notice_to_user.published_by," +
            "                ejyy_notice_tpl.tpl," +
            "                ejyy_notice_tpl.content as tpl_content," +
            "                ejyy_property_company_user.real_name" +
            " from ejyy_notice_to_user left join ejyy_notice_tpl on ejyy_notice_tpl.id = ejyy_notice_to_user.notice_tpl_id "+
            " left join ejyy_property_company_user on ejyy_property_company_user.id = ejyy_notice_to_user.created_by "+
            " where ejyy_notice_to_user.id = #{id} and ejyy_notice_to_user.community_id = #{community_id}"
    )
    Map<String,Object> getDetail(@Param("id") Long id, @Param("community_id") Long community_id);
}
